Skip to content

fix(nuxt): sync i18n locale reactively using dependsOn - #16

Merged
javipuche merged 1 commit into
mainfrom
fix/sync-i18n-timing
Mar 10, 2026
Merged

javipuche merged 1 commit into
mainfrom
fix/sync-i18n-timing

Conversation

@javipuche

Copy link
Copy Markdown
Member

Problem\n\nWhen using Valiform with @nuxtjs/i18n, the locale was not updating reactively when switching languages. The root cause was a plugin initialization order issue: Valiform's Nuxt plugin was running before @nuxtjs/i18n had registered nuxtApp.$i18n, so $i18n was undefined at setup time.\n\n## Solution\n\nSplit the Nuxt runtime plugin into two variants:\n- plugin.ts — used when @nuxtjs/i18n is not installed\n- plugin-i18n.ts — used when @nuxtjs/i18n is installed; declares dependsOn: ['i18n:plugin'] so Nuxt guarantees $i18n is ready before Valiform runs\n\nThe module (nuxt/module.ts) dynamically selects which plugin to register using hasNuxtModule('@nuxtjs/i18n') from @nuxt/kit. This ensures Valiform works correctly in both scenarios without breaking projects that don't use i18n.\n\nShared setup logic was extracted to nuxt/runtime/setup.ts to avoid duplication.

@javipuche
javipuche force-pushed the fix/sync-i18n-timing branch from 5499bc3 to 5044b11 Compare March 10, 2026 10:41
@javipuche
javipuche merged commit 352d115 into main Mar 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant